package com.xuxin.queue.utils;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.xuxin.queue.alipay.OrderInfoUtil2_0;
import com.xuxin.queue.base.BaseParam;

import java.util.Map;

/**
 * Created by xu_xin
 * Created on 2020.08.01 0001
 */
public class BaseUtils {

    public static void init(RecyclerView view) {
        view.setLayoutManager(new LinearLayoutManager(view.getContext()));
        view.setItemViewCacheSize(20);
        view.setNestedScrollingEnabled(false);
    }

    public static void init(RecyclerView view, int num) {
        view.setLayoutManager(new GridLayoutManager(view.getContext(), num));
        view.setItemViewCacheSize(20);
        view.setNestedScrollingEnabled(false);
    }

    public static void horizontal(RecyclerView view) {
        LinearLayoutManager manager = new LinearLayoutManager(view.getContext());
        manager.setOrientation(LinearLayoutManager.HORIZONTAL);
        view.setLayoutManager(manager);
        view.setItemViewCacheSize(20);
        view.setNestedScrollingEnabled(false);
    }

    @SuppressWarnings("unchecked")
    public static <T> T cast(Object obj) {
        return (T) obj;
    }


    public static String getAliOrderParam() {
        Map<String, String> params = OrderInfoUtil2_0.buildOrderParamMap(BaseParam.AliPay_id, true);
        String orderParam = OrderInfoUtil2_0.buildOrderParam(params);
        String sign = OrderInfoUtil2_0.getSign(params, BaseParam.AliPay_rsa2, true);
        return orderParam + "&" + sign;
    }
}